<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@include file="/commons/inc.jsp" %>
<script language="javascript" type="text/javascript" src="${contextPath}/js/My97DatePicker/WdatePicker.js"></script>
<script language="javascript" type="text/javascript" src="${contextPath}/js/ajax.js"></script>
<h3 id="navTitleId">患者列表
<font size="2">&nbsp;&nbsp;&nbsp;&nbsp;<font color="red">${count}</font>条记录</font>
<input type="button" value="新增患者信息" class="filterbutton" id="insertBt" onclick="insertNew();">
</h3>
<div id="resultId" style="" >

<%@include file="/commons/showmessage.jsp" %>

<form class="filterform"  id="SearchForm" name="SearchForm" action="${contextPath}/patient/patient.action">
<input type="hidden" name="method" value="query" id="method"/>
<input type="hidden" name="orderCol" id="orderCol"/>
<table cellspacing="0" border="0" cellpadding="0" class="filtertable">
	<tbody>
		<tr>
		<td><label for="searchString" style="font-weight: bold;">编号</label></td>	
		<td><input type="text" value="${patientid}" id="sg_searchString" name="patientid" size="10"></td>
		<td><label for="searchString" style="font-weight: bold;">&nbsp;&nbsp;姓名</label></td>	
		<td><input type="text" value="${patientname}" id="sg_searchString" name="patientname" size="18"></td>
		<td><label for="searchString" style="font-weight: bold;">&nbsp;&nbsp;证件号</label></td>	
		<td><input type="text" value="${crenum}" id="sg_searchString" name="crenum" size="25"></td>
		<td><input type="button" value="检索" class="filterbutton" id="searchBt" onclick="searchPatient();"></td>
		</tr>
	</tbody>
</table>
</form>

<form id="listForm" name="listForm" method="post">
<table border="0" cellspacing="1" cellpadding="0" class="formTable" width="100%" >
      <thead>
        <tr>
          <td width="50" align="center" class="form-th">编号</td>
          <td width="50"  align="center" class="form-th">姓名</td>
		  <td width="160" align="center" class="form-th">家庭住址</td>
          <td width="80"  align="center" class="form-th">联系电话</td>
          <td width="75"  align="center" class="form-sort-th" onclick="tbSort('followTime');">随访时间
          	<s:if test="orderCol=='followTime'">
          		<s:if test="ascOrDesc=='DESC'"><img src="${contextPath }/images/sort_desc.png" width="13" height="13" border="0" /></s:if>
          		<s:else><img src="${contextPath }/images/sort_asc.png" width="13" height="13" border="0" /></s:else>
          	</s:if>
          </td>
          <td width="40"  align="center" class="form-th">状态</td>
          <td width="95"  align="center" class="form-th">操作</td>
        </tr>
      </thead>
      <tbody>
     
      <s:iterator value="#request.result" >
       <tr>
         <td align="left" class="form-td">${patientid}</td>
         <td align="left" class="form-td">${patientname}</td>
         <td align="left" class="form-td">${address}</td>
         <td align="left" class="form-td">${telephone}</td>
         <td align="left" class="form-td">${followtime}</td>
         <td align="left" class="form-td">
          <s:if test="patientstatus==1"><font color="#8F4586">进行中</font></s:if>
		  <s:elseif test="patientstatus==2"><font color="#2828FF">失访</font></s:elseif>
		  <s:elseif test="patientstatus==3"><font color="#FF8000">结束</font></s:elseif>
		  <s:elseif test="patientstatus==4"><font color="red">完成</font></s:elseif>
		  <s:elseif test="patientstatus==5"><font color="red">死亡</font></s:elseif>
		  <s:else><font color="#8F4586">未知</font></s:else></td>
         <td align="left" class="form-td">
         	<a href="javascript:void(0);" onclick="doEdit(${patientid},1); return false">基线信息</a>&nbsp;&nbsp;
         	|&nbsp;&nbsp;<a href="javascript:void(0);" onclick="doEdit(${patientid},2); return false">随访信息</a>
         	|&nbsp;&nbsp;<a href="javascript:void(0);" onclick="delPatient(${patientid}); return false">删除患者</a></td>
         </tr>
      </s:iterator>   
      
      </tbody>
    </table>

	 <s:if test="#request.page.totalPage>1">
        <s:url id="url_page" action="patient.action" namespace="/patient" escapeAmp="false">
         		<s:param name="page" value="'#pageNumber#'" />
         </s:url>     
         <s:set name="url_page" value="@org.apache.commons.lang.StringUtils@replace(#url_page, '%23', '#')"/>
        <div class="page">
			<q:page url="${url_page}" page="${page}"/>
		</div>    
	</s:if> 
</form> 
<div style="display:block; height:10px;"></div>
</div>

<script>
function insertNew(){
	location.href="${contextPath}/patient/patient.action?method=insertNewPatient";
}

function searchPatient(){
	document.SearchForm.submit();
}

function doEdit(id, flag){
	location.href="${contextPath}/patient/patient.action?method=editPatient&patientid="+id+"&flag="+flag;
}
function delPatient(id){
	 if(!confirm("确认删除该患者?")){
		return false;
	 }
	 var ajax = new postAjax();
	 url = "patient/patient.action?method=delPatient&";
	 value = "patientid=" + id;
	  ajax.connect(url,value,delCallback);
	/*  
	  var postData = "&patientid="+id;
      new Request({url: "${contextPath}/patient/patient.action?method=delPatient" + postData, callback: function(){
		if(this.jsonObject.errorMessage){
			this.showError(this.jsonObject.errorMessage);
		}else{
			location.href="${contextPath}/patient/patient.action?method=query";
		}						
 	  },action:'statusBar'}); */
    	 
    	 
}
function delCallback(xmlHttp){
	var re = xmlHttp.responseText;
	if(re!=null &&re!=""){
		var msg = eval("("+re+")"); 
		if(msg!=null){
			if(msg.errorMessage!=''){
				showError($('statusBar'), "删除出错");	
			}else if(msg.successMessage!=''){
				location.href="${contextPath}/patient/patient.action?method=query";
				showSuccess($('statusBar'), "删除成功");	
			}
		} 
	} 
	return;
}
</script>